#include "CServer.h"
#include "const.h"
#include "ConfigMgr.h"
#include "RedisMgr.h"

int main() {

	ConfigMgr& gCfgMgr=ConfigMgr::Inst();
	std::string gate_port_str = gCfgMgr["GateServer"]["Port"];
	unsigned short gate_port = atoi(gate_port_str.c_str());
	try {
		boost::asio::io_context ioc{ 1 };
		boost::asio::signal_set signals(ioc, SIGINT, SIGTERM);
		signals.async_wait([&ioc](const boost::system::error_code& error, int signal_number) {
			if (error) {
				return;
			}
			ioc.stop();
			});
		std::cout << "The server has started, listening on port 8080..." << std::endl;
		std::make_shared<CServer>(ioc, gate_port)->Start();
		ioc.run();
	}
	catch (std::exception& e) {
		std::cout << "Error: " << e.what() << std::endl;
		return EXIT_FAILURE;
	}
}